package com.cc.test;

import com.cc.utils.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @User: c.c
 * @Date: 2022/6/28
 * @Time: 10:13
 * @Description:
 */

public class testTree {
  public static void main(String[] args) {
    UserDto userDto = new UserDto("001-001","0","一班班长","一班");
    UserDto userDto1 = new UserDto("001-002","001-001","纪律委员","一班_委员");
    UserDto userDto2 = new UserDto("001-003","001-001","劳动委员","一班_委员");
    UserDto userDto3 = new UserDto("001-004","001-001","体育委员","一班_委员");
    UserDto userDto4 = new UserDto("001-005","001-001","学习委员","一班_委员");
    UserDto userDto5 = new UserDto("001-006","001-005","小明","一班_群众");
    UserDto userDto6 = new UserDto("001-007","001-002","小红","一班_群众");
    UserDto userDto7 = new UserDto("002-001","0","二班班长","二班");


    ArrayList<UserDto> stdudents = new ArrayList<>();
    stdudents.add(userDto);
    stdudents.add(userDto1);
    stdudents.add(userDto2);
    stdudents.add(userDto3);
    stdudents.add(userDto4);
    stdudents.add(userDto5);
    stdudents.add(userDto6);
    stdudents.add(userDto7);

    List<TreeNode<UserDto>> treeNodes = TreeNode.buildListTree(stdudents);
    System.out.println("广度遍历");
    for (TreeNode<UserDto> treeNode : treeNodes) {
      System.out.println("当前组织："+treeNode.getData().getOrganization());
      System.out.println("父类名字_子类名字");

      treeNode.bfsEach(child -> {
        switch (child.getLevel()){
          case 1 :
            System.out.println("\t"+"null"+" _ "+child.getData().getName());
            break;
          case 2:
            System.out.println("\t"+"\t"+child.getParent().getData().getName()+" _ "+child.getData().getName());
            break;
          case 3:
            System.out.println("\t"+"\t"+"\t"+child.getParent().getData().getName()+" _ "+child.getData().getName());
            break;
        }
      });
    }

    System.out.println();
    System.out.println("*********************分割***********************");
    System.out.println();

    System.out.println("----------------深度遍历-----------------------");
    for (TreeNode<UserDto> treeNode : treeNodes) {
      System.out.println("当前组织："+treeNode.getData().getOrganization());
      System.out.println("父类名字_子类名字");
      treeNode.dfsEach(child -> {
        switch (child.getLevel()){
          case 1 :
            System.out.println("\t"+"null"+" _ "+child.getData().getName());
            break;
          case 2:
            System.out.println("\t"+"\t"+child.getParent().getData().getName()+" _ "+child.getData().getName());
            break;
          case 3:
            System.out.println("\t"+"\t"+"\t"+child.getParent().getData().getName()+" _ "+child.getData().getName());
            break;
        }
      });
    }
  }
}
